package com.neusoft.neuiotms.dcom.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractModel;
import com.neusoft.neuiotms.dcom.model.enums.QuestionnaireScope;
import com.neusoft.neuiotms.dcom.model.enums.QuestionnaireType;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Entity
@org.hibernate.annotations.Table(appliesTo = "hainan_questionnaire", comment = "任务下发")
@Table(name = "hainan_questionnaire")
public class Questionnaire extends AbstractModel {

    private static final long serialVersionUID = 1L;

    /** 运维小组 */
    @NotBlank(message = "运维小组不能为空")
    @Length(max = 255, message = "运维小组不能超过{max}位")
    @Column(length = 255, nullable = false)
    private String groupCode;

    /** 标题 */
    @NotBlank(message = "标题不能为空")
    @Length(max = 255, message = "标题不能超过{max}位")
    @Column(length = 255, nullable = false)
    private String title;

    /** 年 */
    private int year = 0;

    /** 适用范围 */
    @Enumerated(EnumType.STRING)
    @NotNull(message = "适用范围不能为空")
    @Column(nullable = false)
    private QuestionnaireScope scope = QuestionnaireScope.WORKER;

    /** 下发任务类型 */
    @Enumerated(EnumType.STRING)
    @NotNull(message = "任务类型不能为空")
    @Column(nullable = false)
    private QuestionnaireType type;

    /** 上报详情 */
    @OneToMany(mappedBy = "questionnaire", cascade = {CascadeType.ALL })
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<QuestionnaireFeedback> feedbacks = new ArrayList<>();

    /** 截止时间 */
    @NotNull
    @Column(nullable = false)
    private Date closedAt;

    private boolean published = false;

    /** 发布时间 */
    @Column(nullable = true)
    private Date publishAt;
}
